home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / MISCEOUS / YRCAL17T.LZH / YRCLANN.C < prev    next >
Text File  |  1989-10-02  |  6KB  |  210 lines

  1. /********************************************************************
  2. **  YRCLANN.C v0.17T  Copyright (c) 1987, 1988, 1989 by Paul M. Sittler.
  3. **
  4. **  Produces Annual and Fiscal Year calendars for YEARCAL.
  5. **
  6. **  All rights reserved.  The copyright owner hereby authorizes the
  7. **  no-charge, noncommercial making and/or distribution of copies of
  8. **  the entirety of this work unchanged and unincorporated in any
  9. **  other work (except "LiBRary" or "ARChive" disk files for the sole
  10. **  purpose of no-charge noncommercial distribution).  No other
  11. **  reproduction or use is authorized without the express prior
  12. **  written consent of the copyright owner.
  13. **
  14. **************************************************************/
  15.  
  16. /* ANSI header files included:  */
  17. #include <stdio.h>    /* fclose, fopen, fp, fprintf, fputs, */
  18.             /* gets, printf, rename, sprintf, stderr */
  19. #include <stdlib.h>    /* exit */
  20. #include <string.h>    /* strcat, strcmp, strcpy, strlen */
  21.  
  22. #include "yearcal.def"
  23.  
  24. /* External variables and structures declared in YEARCAL.C */
  25. extern struct month mon[];        /* Month's lengths array */
  26. extern char *lingo[];            /* Names of languages array */
  27. extern char *mnam[][12];        /* Names of months array */
  28. extern char *wkday[][7];        /* Names of days array */
  29. extern int yr[][12][6][7];        /* Array for 3 yrs, 4-D, */
  30.                     /* 3 years,      12 months/year, */
  31.                     /* 6 weeks/month, 7 days/week */
  32. extern char *new_file;
  33. extern char *file;
  34. extern FILE *fp;
  35.  
  36.  
  37.  
  38. void cal_printer(int year, char out,  int bm,   char fy,
  39.          int bd,   char base, int lang, char pause)
  40. /* char base;    Number base used, 0 = Decimal, H = Hex, O = Octal */
  41. /* int lang;    Language used 1=Danish, 2=Dutch, 3=English etc. */
  42. /* char pause;    Page pause True/False */
  43. {
  44.     char hdr1[] = {" Su Mo Tu We Th Fr Sa"},
  45.      hdr2[] = {" -- -- -- -- -- -- --"};
  46.  
  47.     int y,
  48.     month,
  49.     week,
  50.     day,
  51.     count,
  52.     stat;
  53.     char  linbuf[BUF],
  54.       temp[BUF];
  55.  
  56.     char *off = (out == 'V') ?
  57.              " " :
  58.            "       "  ;
  59.  
  60.     y = 1;                /* Make year this year */
  61.  
  62.     sprintf(hdr1, " %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s",
  63.        wkday[lang - 1][0], wkday[lang - 1][1], wkday[lang - 1][2],
  64.        wkday[lang - 1][3], wkday[lang - 1][4], wkday[lang - 1][5],
  65.        wkday[lang - 1][6] );
  66.  
  67.     if (out == 'F')            /* Setup for file output */
  68.     {
  69.     sprintf(file, fy ? "%dFY%c" :
  70.                "%d%c",    year, base);
  71.     strcpy(new_file, file);
  72.     strcat(file, ".$$$");
  73.     sprintf(temp, ".%3.3s", lingo[lang - 1]);
  74.     strcat(new_file, temp);
  75.     fp = fopen(file, "w");
  76.     }
  77.  
  78.     if (pause     &&            /* User wants time after each page */
  79.     out == 'P' )            /* Gets printed to add paper etc... */
  80.     hold();                /* Wait for keystroke */
  81.  
  82.     fputs("\n\n\n", fp);
  83.     sprintf(temp, fy ? "%s%s%s Calendar for Fiscal Year %d-%d":
  84.                "%s%s%s Calendar for %d",
  85.          base ? "Programmer's " :
  86.             "" ,
  87.          base ? ( (base == 'O') ? "Octal "      :
  88.                       "Hexadecimal " ) :
  89.                       "",
  90.          lingo[lang - 1],
  91.          year, year + 1);
  92.  
  93.     fputs(center(temp, (out == 'V') ?
  94.                  75 :
  95.                  89 ), fp);
  96.     fputs("\n\n\n", fp);
  97.  
  98.     if (bd == 1)            /* If fy month starts on 1st, */
  99.     fy = FALSE;            /*   treat like ordinary month */
  100.  
  101.     for (month = bm;            /* Start at beginning Month for FY */
  102.      month < (12 + bm + fy);
  103.      month += 3)
  104.     {                    /* 4 sets of months */
  105.                     /* 3 months across */
  106.     sprintf(linbuf,
  107.          "%s%s    ",
  108.           off,
  109.         center(mnam[lang - 1][month % 12], 21));
  110.  
  111.     if (month != (bm + 12))        /* NOT FY and 13th month */
  112.     {
  113.         sprintf(temp,
  114.         "%s    ",
  115.          center(mnam[lang - 1][(month + 1) % 12], 21));
  116.         strcat(linbuf, temp);
  117.         sprintf(temp,
  118.         "%s"    ,
  119.          center(mnam[lang - 1][(month + 2) % 12], 21));
  120.         strcat(linbuf, temp);
  121.     }
  122.  
  123.     strcat(linbuf, "\n");        /* Add a newline */
  124.     fputs(linbuf, fp);        /* Names of three Months */
  125.     linbuf[0] = '\0';
  126.  
  127.     if (month != (bm + 12))        /* NOT FY and 13th month */
  128.     {
  129.         fprintf(fp, "%s%s    %s    %s\n",
  130.             off, hdr1, hdr1, hdr1);
  131.         fprintf(fp, "%s%s    %s    %s\n",
  132.             off, hdr2, hdr2, hdr2);
  133.     }
  134.     else                /* FY and 13th month */
  135.     if (bd != 1)            /* Beginning after the 1st */
  136.     {
  137.         fprintf(fp, "%s%s\n",    /* Names of weekdays */
  138.             off, hdr1);
  139.         fprintf(fp, "%s%s\n",    /* Lines of dashes */
  140.             off, hdr2);
  141.     }
  142.  
  143.     for (week = 0;            /* One line per week */
  144.          week < 6;            /* 6 wks/month possible */
  145.          week++)
  146.     {
  147.         sprintf(linbuf, off);
  148.  
  149.         for (count = 0;        /* 3 months/line ordinarily */
  150.          count < ((month == (bm + 12)) ?
  151.                         1 : /* FY 13th month alone */
  152.                         3); /* Ordinary line */
  153.          count++)
  154.         {
  155.         for (day = 0;
  156.              day < 7;        /* 7 days/week */
  157.              day++)
  158.         {
  159.             if (((month + count) == bm) &&  /* FY 1st month */
  160.             (yr[y][month + count][week][day] < bd))
  161.              sprintf(temp, "   ");
  162.             else
  163.             if (((month + count) == (bm + 12)) &&
  164.             (yr[y][month + count][week][day] >= bd))
  165.              sprintf(temp, "   ");
  166.             else
  167.             sprintf(temp,
  168.             yr[y][month + count][week][day] ?
  169.                 (base ?
  170.                 ((base == 'O') ?
  171.                      "%3o" :
  172.                      "%3X" ) :
  173.                      "%3d" ) :
  174.                      "   ",
  175.             yr[y][month + count][week][day]);
  176.  
  177.             strcat(linbuf, temp);
  178.         }
  179.  
  180.         strcat(linbuf,
  181.         count < ((month < (bm + 12)) ?
  182.                       2 : 0) ?
  183.                        "    ":
  184.                        "\n"  );
  185.         }
  186.  
  187.         fputs(linbuf, fp);
  188.         linbuf[0] = '\0';
  189.     }
  190.     fputs("\n\n", fp);
  191.     }
  192.     if (out != 'V')
  193.     fputs("\f\r", fp);        /* No FF for screen */
  194.  
  195.     if (out == 'F')            /* Setup for file output */
  196.     if ((stat = fclose(fp)) == ERROR)
  197.         printf("\nCan't close %s.\n", file);
  198.  
  199.     if (out == 'F')
  200.     {
  201.     if ((stat = rename(file, new_file)) == ERROR)
  202.     {
  203.         printf(
  204.         "\nCan't rename %s to %s.  %s may already exist.\n",
  205.                 file, new_file,
  206.                        new_file);
  207.     }
  208.     }
  209. }
  210.